
// 格式化时间
export const formatTime = (val, fmt) => {
	if (val == null) {
		return null;
	}
	let date = new Date(val);
	let years = date.getFullYear();
	let month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : `0${date.getMonth() + 1}`;
	let day = date.getDate() > 9 ? (date.getDate()) : `0${date.getDate()}`;
	let hours = date.getHours() > 9 ? (date.getHours()) : `0${date.getHours()}`;
	let mins = date.getMinutes() > 9 ? (date.getMinutes()) : `0${date.getMinutes()}`;
	let seconds = date.getSeconds() > 9 ? (date.getSeconds()) : `0${date.getSeconds()}`;
	if (fmt == 'YYYY-MM-DD hh:mm:ss') {
		return `${years}-${month}-${day} ${hours}:${mins}:${seconds}`;
	}
    if (fmt == 'YYYY-MM-DD') {
		return `${years}-${month}-${day}`;
	}
	if (fmt == 'YYYY-MM') {
		return `${years}-${month}`;
	}
	if (fmt == 'MM-DD') {
		return `${month}月${day}日`;
	}
	return `${years}-${month}-${day} ${hours}:${mins}:${seconds}`;
};